<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="供客名称" prop="supplyName">
        <el-input
          v-model="queryParams.supplyName"
          placeholder="请输入供客名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供客类型" prop="isType">
        <el-select
          placeholder="请选择供客类型"
          v-model="queryParams.isType"
          @keyup.enter.native="handleQuery"
        >
          <el-option label="供应商" value="1" />
          <el-option label="客户" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="qkList">
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="供客名称" align="center" prop="supplyName" />
      <el-table-column label="欠款金额" align="center" prop="qkPrice">
         <template slot-scope="scope">
          <span style="color: red;">{{scope.row.qkPrice}}</span>
         </template>
      </el-table-column>

      <el-table-column
        label="供客类型"
        align="center"
        prop="isType"
        width="150"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isType === '1'">供应商</el-tag>
          <el-tag type="success" v-if="scope.row.isType === '2'">客户</el-tag>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listQk } from "@/api/supermarket/qk";

export default {
  name: "Qk",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供客欠款表格数据
      qkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplyName: null,
        supplyId: null,
        qkPrice: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询供客欠款列表 */
    getList() {
      this.loading = true;
      listQk(this.queryParams).then((response) => {
        this.qkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        qkId: null,
        supplyName: null,
        supplyId: null,
        qkPrice: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
